namespace FluentBinding.WinForms
{
    /// <summary>
    /// Implementation of the IDataMemberConvertor which uses IPropertyConvertor supplied by user
    /// </summary>
    /// <typeparam name="E">Type of the root entity</typeparam>
    /// <typeparam name="P">Type of the property in the entity</typeparam>
    internal class PropertyConvertorAdapter<E, P> : IDataMemberConvertor<E>
    {
        #region Fields

        private readonly IPropertyConvertor<E, P> _propertyConvertor;

        #endregion

        #region Constructors

        public PropertyConvertorAdapter(IPropertyConvertor<E, P> propertyConvertor)
        {
            _propertyConvertor = propertyConvertor;
        }

        #endregion

        #region IDataMemberConvertor<E> Members

        public object Select(E entity)
        {
            return _propertyConvertor.Select(entity);
        }

        public void Initialize(E entity, object value)
        {
            _propertyConvertor.Initialize(entity, (P)value);
        }

        #endregion
    }
}